import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
  notes: [],
  activeNote: {},
  show: '',
  tabOptions : [],
  activeTabs : '',
};

const mutations = {
    ADD_TABS : (state,data) => {/*增加*/
      let noRepeat = state.tabOptions.every(function(elem){
        return elem.path !== data.path
      });
      if(noRepeat){
        state.tabOptions.push(data);
        let JSONdata = JSON.stringify(state.tabOptions);
        window.sessionStorage.setItem('tabList',JSONdata);
      }
    },
    DELETE_TABS : (state,data) => {/*删去*/
      state.tabOptions.forEach(function(elem,index){
        if(elem.path === data){
          state.tabOptions.splice(index,1);
          let JSONdata = JSON.stringify(state.tabOptions);
          window.sessionStorage.setItem('tabList',JSONdata);
        }
      })
    },
    SET_ACTIVE_INDEX (state, val) {/*设置当前*/
      state.activeTabs = val;
      let JSONdata = JSON.stringify(state.activeTabs);
      window.sessionStorage.setItem('activeTab',JSONdata);
    },
}